From 0d58aa752d8d8ec96fc450958d428c40a620ac6b Mon Sep 17 00:00:00 2001 From: robertl Date: Sun, 15 Feb 2004 19:04:52 +0000 Subject: [PATCH] Give error when no filename is passed to xfopen. Magellan/windows - fix crash opening non-existent file. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@705 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/Makefile | 6 +++--- gpsbabel/magproto.c | 4 ++-- gpsbabel/util.c | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gpsbabel/Makefile b/gpsbabel/Makefile index 7167fa63d..2a1c8376c 100644 --- a/gpsbabel/Makefile +++ b/gpsbabel/Makefile @@ -3,7 +3,7 @@ # type that is XML-ish (i.e. gpx or geocaching.com's/loc) you can uncomment # INHIBIT_EXPAT and coment out LIBEXPAT on just to get a build working quickly. # INHIBIT_EXPAT=-DNO_EXPAT -LIBEXPAT=-lexpat # -lefence +LIBEXPAT=-lexpat #-lefence # # Enable either or both of these as you wish. @@ -78,8 +78,8 @@ dep: (echo -n "internal_styles.c: mkstyle.sh " ; echo style/*.style ; /bin/echo -e '\t./mkstyle.sh > $@ || (rm -f $@ ; exit 1)' ) >> /tmp/dep echo Edit Makefile and bring in /tmp/dep -VERSIONU=1_2_1_beta01312004 -VERSIOND=1.2.1_beta01312004 +VERSIONU=1_2_2_beta02152004 +VERSIOND=1.2.2_beta02152004 #VERSIONU=1_2_1 #VERSIOND=1.2.1 diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 1db4b91a8..c0f099452 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -508,8 +508,7 @@ terminit(const char *portname) OPEN_EXISTING, 0, NULL); if (comport == INVALID_HANDLE_VALUE) { - is_file = 1; - return 0; + goto try_as_file; } tio.DCBlength = sizeof(DCB); GetCommState (comport, &tio); @@ -537,6 +536,7 @@ terminit(const char *portname) /* * Probably not a com port. Try it as a file. */ +try_as_file: magfile_in = xfopen(portname, "rb", MYNAME); is_file = 1; icon_mapping = map330_icon_table; diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 354ace1c3..bbdc53fbf 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -230,6 +230,11 @@ xfopen(const char *fname, const char *type, const char *errtxt) FILE *f; int am_writing = strchr(type, 'w') != NULL; + if (fname == NULL) { + fatal("%s must have a filename specified for %s.\n", + errtxt, am_writing ? "write" : "read"); + } + if (0 == strcmp(fname, "-")) return am_writing ? stdout : stdin; f = fopen(fname, type); -- 2.30.2